<?php

class User extends BaseModel {
    public static $_table = 'AppUsers';
    public static $_id_column = 'email';

    /**
     * Validates the model.
     * Any errors found will be returned as a field => description array
     */
    public function validate() {
        $errors = array();

        $existing = Model::factory('User')->where('email', $this->email)->find_one();

        if(!empty($existing)) {
            $errors['email'] = 'Email already in use';
        }

        return $errors;
    }

    public static function orm() {
        return self::factory(__CLASS__);
    }

}
